<template>
  <div :style="{width:'100%',height:'100%'}" ref="homeEch"></div>
</template>

<script>
export default {
  name: "Age",
  data() {
    return {
      data: [
      ],
      agelist: [{}]
    };
  },
  created() {
    // this.echarts();
  },
  mounted() {  
    this.echarts();
    this.resizefun = () => {
      this.$echarts.init(this.$refs.homeEch).resize();
    };
    window.addEventListener("resize", this.resizefun);
  },
  //移除事件监听，避免内存泄漏
  beforeDestroy() {
    window.removeEventListener("resize", this.resizefun);
    this.resizefun = null;
  },
  methods: {
    // 年龄比例接口
    echarts() {
        // let that = this;
      let myChart = this.$echarts.init(this.$refs.homeEch);
        var option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'horizontal',
                top: 0,
                data: ['男性', '女性'],
                textStyle: {
                    color: "#fff"
                }
            },
            series: [
                {
                    itemStyle: {
                        normal: {
                            label: {
                                show: false
                            },
                            labelLine: {
                                show: false
                            }
                        }
                    },
                    name: '',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: [
                        {
                            value: 1359, name: '男性',
                            itemStyle: {
                                normal: {
                                    color: "#2865aa"
                                }
                            }
                        },
                        {
                            value: 576, name: '女性',
                            itemStyle: {
                                normal: {
                                    color: "#ff81cb"
                                }
                            }
                        }
                    ]
                }
            ]
        };



        myChart.setOption(option);
    }

  }
};
</script>

<style>
</style>